package com.epay;

import java.io.File;
import java.io.FileWriter;

public class CreaterService {

	public static boolean createrService(){
		try{
			 String workpath = Constants.workpath;
			 String tableNameLower=Constants.fileName;
			 String tableName=tableNameLower.substring(0,1).toUpperCase()+tableNameLower.substring(1);
			 //创建service文件
			 String dir = workpath + File.separator + CreaterUtil.replaceAll(Constants.business_package, ".", File.separator);
		     File dirfile = new File(dir);
		     if (!dirfile.exists()) {
		       dirfile.mkdirs();
		     }
		     
		     File beanfile = new File(dir+"/" + tableName+"Service.java");
		     FileWriter fw2 = new FileWriter(beanfile);
		     fw2.write("package " + Constants.business_package + ";\n");
		     fw2.write("import com.epay.common.base.BaseService;\n");
		     fw2.write("import "+Constants.searchModel_package+"."+tableName+"DO;\n");
		     fw2.write("\n");
		     fw2.write("/**\n");
			 fw2.write(" * 业务接口\n");
			 fw2.write(" * @author Epay\n");
			 fw2.write(" * @date "+Constants.getSysDate()+"\n");
		     fw2.write(" */\n");
		     fw2.write("public interface " + tableName + "Service extends BaseService<" + tableName + "DO>{");
		     fw2.write("\n");
		     
		    

			 fw2.write("}\n");
			 fw2.close();
			 
			 
			 
			 
			 
			 
			 String  thisDao=tableNameLower+"Dao";
			 //创建service文件
			 String dir1 = workpath + File.separator + CreaterUtil.replaceAll(Constants.business_service_package, ".", File.separator);
		     File dirfile1 = new File(dir1);
		     if (!dirfile1.exists()) {
		       dirfile1.mkdirs();
		     }
		     File beanfile1 = new File(dir1+"/" + tableName+"ServiceImpl.java");
		     FileWriter fw1 = new FileWriter(beanfile1);
		     fw1.write("package " + Constants.business_service_package + ";\n");
		     fw1.write("import javax.annotation.Resource;\n");
		     fw1.write("import org.springframework.stereotype.Service;\n");
		     fw1.write("import com.epay.common.base.BaseServiceImpl;\n");
		     fw1.write("import "+Constants.searchModel_package+"."+tableName+"DO;\n");
		     fw1.write("import "+Constants.business_package+"."+tableName+"Service;\n");
		     fw1.write("import "+Constants.dao_package+"."+tableName+"Dao;\n");
		     fw1.write("\n");
		     fw1.write("/**\n");
			 fw1.write(" * 业务接口\n");
			 fw1.write(" * @author Epay\n");
			 fw1.write(" * @date "+Constants.getSysDate()+"\n");
		     fw1.write(" */\n");
		     fw1.write("@Service\n");
		     fw1.write("public class " + tableName + "ServiceImpl extends BaseServiceImpl<"+tableName+"Dao, "+tableName+"DO> implements "+tableName+"Service{\n");
		     fw1.write("\n");
		     fw1.write("\t@Resource\n");
		     fw1.write("\tprivate "+tableName+"Dao "+thisDao+";\n");
		    
			 fw1.write("}\n");
			 fw1.close();
			 
		}catch(Exception e){
			System.out.println("创建bean异常");
			e.printStackTrace();
		}
		return true;
	}
}
